﻿using NHibernate;
using SmartRS.com.vn.smartrs.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartRS.com.vn.smartrs.dao
{
    public class FoodOrderDao : BaseDao<FoodOrder>
    {
        private static FoodOrderDao _foodOrderDao = new FoodOrderDao();

        private FoodOrderDao()
        { }

        public static FoodOrderDao getInstance()
        {
            return _foodOrderDao;
        }

        public IList<FoodOrder> getListByBillId(long billId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                try
                {
                    var result = session.QueryOver<FoodOrder>().Where(x => x.bill.billId == billId && x.deteleFlag == false).List<FoodOrder>();
                    return result;
                }
                catch (Exception ex)
                {
                    throw new Exception("getListByBillId happened error: " + ex.Message);
                }
            }
        }

        public FoodOrder getFoodOrder(long foodId, long billId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                try
                {
                    var result = session.QueryOver<FoodOrder>().Where(x => x.bill.billId == billId && x.food.foodId == foodId && x.deteleFlag == false).List<FoodOrder>();
                    return (null != result && result.Count > 0) ? result[0] : null;
                }
                catch (Exception ex)
                {
                    throw new Exception("getFoodOrder happened error: " + ex.Message);
                }
            }
        }
    }
}
